package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.aliyun.iot20180120.models.QueryThingModelPublishedResponseBody;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/iot")
@Api(tags = "设备管理")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    @ApiOperation(value = "同步产品列表")
    public ResponseResult syncProductList(){
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    @GetMapping("/allProduct")
    @ApiOperation(value = "获取所有产品")
    public ResponseResult allProduct(){
       List<ProductVo> list = deviceService.allProduct();
        return ResponseResult.success(list);
    }

    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "注册设备")
    public ResponseResult RegisterDevice(@RequestBody DeviceDto deviceDto){
        deviceService.RegisterDevice(deviceDto);
        return ResponseResult.success();
    }

    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询设备")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice( DevicePageQueryDto devicePageQueryDto){
        PageResponse<DeviceVo>  list =  deviceService.pageQueryDevice(devicePageQueryDto);
        return ResponseResult.success(list);
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "查询设备详情")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData> QueryDevicePropertyStatus(@RequestBody DeviceDto deviceDto){
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData list = deviceService.queryDevicePropertyStatus(deviceDto);
        return ResponseResult.success(list);
    }

    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult<Map<String, Object>> QueryThingModelPublished(@RequestBody DeviceDto deviceDto){
        Map<String, Object> data = deviceService.queryThingModelPublished(deviceDto);
        return ResponseResult.success(data);
    }

    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "修改设备备注名称")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto){
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/DeleteDevice")
    @ApiOperation(value = "删除设备")
    public ResponseResult deleteDevice(@RequestBody DeviceDto deviceDto){
        deviceService.deleteDevice(deviceDto);
        return ResponseResult.success();
    }
}
